<?php
/*-------------------------------------------------------------------------\
|
|  ========================================================
|  Fusion Registry GPL
|  Copyright (C) 2007 Fusion Scripts
|
|  This program is free software; you can redistribute it and/or
|  modify it under the terms of the GNU General Public License
|  as published by the Free Software Foundation; either version 2
|  of the License, or (at your option) any later version.
|
|  This program is distributed in the hope that it will be useful,
|  but WITHOUT ANY WARRANTY; without even the implied warranty of
|  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
|  GNU General Public License for more details.
|
|  You should have received a copy of the GNU General Public License
|  along with this program; if not, write to the Free Software
|  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
|  ========================================================
|
|  Email: info@fusionscripts.com
|  Web-Site: http://www.fusionscripts.com/
|
|  $Id: registrysessions.php 4 2008-08-03 01:43:03Z registry.fusion $
|
\-------------------------------------------------------------------------*/

/**
 * Task file to delete old Fusion Registry sessions stored in the database.
 *
 * Although the session code has a garbage collection routine, this task
 * ensures that cleanup will happen on a regular basis. This task is not
 * required for end users to setup, but is suggested.
 *
 * @package Fusion Registry
 * @subpackage tasks
 * @version $Id: registrysessions.php 4 2008-08-03 01:43:03Z registry.fusion $
 */

if ( ! defined( 'IN_IPB' ) )
{
    print "<h1>Incorrect access</h1>You cannot access this file directly. If you have recently upgraded, make sure you upgraded all the relevant files.";
    exit();
}

/**
 * Delete old Fusion Registry sessions
 *
 * Most of this file is the standard IPB template for tasks
 *
 * @package Fusion Registry
 * @subpackage tasks
 */
class task_item
{
    /**#@+ @var string */
    var $root_path = "";
    var $task      = "";
    /**#@-*/
    
    /** @var object */
    var $class     = "";

    /** @var integer Fusion Registry sessions older than this # seconds will be deleted */
    var $gc_maxlifetime = 1800;

    /**
     * Auto-run our task
     *
     * This is a very simple task - calculate the cutoff time and delete
     */
    function run_task()
    {
        // Calculate the cutoff time
        $date = (time() - $this->gc_maxlifetime);

        // Bye-bye old sessions!
        $this->ipsclass->DB->simple_exec_query( array( 'delete' => 'registry_sessions',  'where'  => "ses_time < $date" ) );

        // Log to log table
        $this->class->append_task_log( $this->task, 'Old Fusion Registry sessions removed' );

		// Unlock Task: DO NOT MODIFY!
		$this->class->unlock_task( $this->task );
    }

    /**
     * register_class - LEAVE ALONE
     *
     * This is part of the IPB task template
     *
     * @param object $class
     */
	function register_class(&$class)
	{
		$this->class     = $class;
		$this->ipsclass  =& $class->ipsclass;
		$this->root_path = $this->class->root_path;
	}

    /**
     * pass_task - LEAVE ALONE
     *
     * This is part of the IPB task template
     *
     * @param object $this_task
     */
    function pass_task( $this_task )
    {
        $this->task = $this_task;
    }

}
?>